package graphing;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import math.functions.Polynomial;
import math.functions.RationalFunction;
import math.statistics.distribution.NormalDistribution;
import java.awt.Color;

/**
 *
 * Fully Tested: No
 * Fully Documented: No
 * Created: 29-May-2012
 * Last Updated: 29-May-2012
 *
 * @author Shimu Wu
 */
public class GraphingProgram extends JFrame{
    
    public GraphingProgram() { 
        setSize(screenX, screenY);
        screenBuffer = new BufferedImage(screenX, screenY,
                BufferedImage.TYPE_INT_ARGB);
        graphics = screenBuffer.createGraphics();
        graph = new Graph(screenX, screenY, graphics);
        
        //addNormalDistributions();
        addPolynomialFunctions();
        //addRationalFunctions();
        
        graph.draw();
        this.setVisible(true);
    }
    
    private static final long serialVersionUID = 1L;

    private BufferedImage screenBuffer;

    private Graphics2D graphics;

    // For Drawing the Asymptote
    private final static int AWidth = 1;

    private final static int AColour = 16;

    private int AY1 = 0;

    private int AY2 = 0;

    private final int screenX = 800; // Length of the screen

    private final int screenY = 800; // Height of the screen

    private Graph graph;

    @SuppressWarnings("unused")
    private void addNormalDistributions(){
        graph.addGraphable(new NormalDistribution(0, 1), Color.BLUE, 2);
        graph.addGraphable(new NormalDistribution(0, 2), Color.ORANGE, 2);
        graph.addGraphable(new NormalDistribution(0, 1.5), Color.MAGENTA, 2);
    }
    
    @SuppressWarnings("unused")
    private void addPolynomialFunctions(){
        graph.addGraphable(Polynomial.LINEAR, Color.BLACK, 2);
        graph.addGraphable(Polynomial.QUADRATIC, Color.GREEN, 2);
        graph.addGraphable(Polynomial.CUBIC, Color.RED, 2);
        //graph.addGraphable(Polynomial.QUARTIC, Color.BLUE, 2);
        //graph.addGraphable(Polynomial.QUINTIC, Color.LIGHT_GRAY, 2);
    }
    
    private void addRationalFunctions(){
        //graph.addGraphable(RationalFunction.DEGREE_1, Color.RED, 2);
        graph.addGraphable(RationalFunction.DEGREE_2, Color.GREEN, 2);
        graph.addGraphable(RationalFunction.DEGREE_3, Color.BLUE, 2);
    }
    
    @Override
    public void paintComponents(Graphics g) {
        super.paintComponents(g);
        g.drawImage(screenBuffer, 0, 0, null);        
    }
    
    public static void main(String[] args) {
        GraphingProgram p = new GraphingProgram();
    }
}
